package com.sctvcloud.dongqu.ui.adapter.holder;

import android.content.Context;
import android.content.Intent;
import android.graphics.Typeface;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.TextUtils;
import android.text.style.StyleSpan;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

import com.canyinghao.canrefresh.CanRefreshLayout;
import com.ruihang.generalibrary.ui.widget.CustomFontTextView;
import com.ruihang.generalibrary.utils.ListUtils;
import com.sctvcloud.dongqu.R;
import com.sctvcloud.dongqu.application.Cache;
import com.sctvcloud.dongqu.beans.HomeListItem;
import com.sctvcloud.dongqu.beans.LiveHomeAdvance;
import com.sctvcloud.dongqu.beans.NewsItem;
import com.sctvcloud.dongqu.ui.activities.ShortMoreActivity;
import com.sctvcloud.dongqu.ui.activities.VideoPlayViewActivity;
import com.sctvcloud.dongqu.ui.adapter.HomeTopNewsListAdapter;
import com.sctvcloud.dongqu.ui.adapter.ShortVideoAdapter;
import com.sctvcloud.dongqu.ui.adapter.ShortVideoNewAdapter;
import com.sctvcloud.dongqu.ui.util.IListShowData;
import com.sctvcloud.dongqu.ui.util.RBaseItemDecoration;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by rh008 on 2017/7/13.
 */

public class ShortHolder extends BaseAbsHolder<LiveHomeAdvance> {

    @BindView(R.id.item_only_title_title)
    protected CustomFontTextView title;

    @BindView(R.id.tv_more)
    protected TextView tv_more;

    @BindView(R.id.can_content_view)
    protected RecyclerView mRecyclerView;

    private ShortVideoNewAdapter mAdapter;


    public ShortHolder(Context context, View itemView) {
        super(context, itemView);
    }

    @Override
    protected void initInject() {
        ButterKnife.bind(this, itemView);
    }

    @Override
    public void setData(LiveHomeAdvance homeListItem) {
        init(homeListItem.getNewsList(),homeListItem.getPageAll());


        Spannable string = new SpannableString("微视频");
            // 粗体
        string.setSpan(new StyleSpan(Typeface.BOLD), 0, string.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
        title.setText(string);
    }



    private void init(final List<NewsItem> list,final int pageAll) {


        mRecyclerView.setItemAnimator(new DefaultItemAnimator());
        mRecyclerView.setLayoutManager(new GridLayoutManager(context, 2));
//        mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false));
        mRecyclerView.addItemDecoration(new RBaseItemDecoration(0));
        mAdapter = new ShortVideoNewAdapter(context, new ShortVideoNewAdapter.OnVideoClickListener() {
            @Override
            public void OnVideoClick(int position) {
                if (ListUtils.isListValued(list)) {
                    Cache.getInstance().setShortVideonList(list);
                    Intent intent = new Intent(context, VideoPlayViewActivity.class);
                    intent.putExtra(VideoPlayViewActivity.JUMP_INTO_INDEX, position);
                    intent.putExtra(VideoPlayViewActivity.JUMP_INTO_PAGE_INDEX, 0);
                    intent.putExtra(VideoPlayViewActivity.JUMP_INTO_PAGEALL_INDEX, pageAll);
                    context.startActivity(intent);
                }
            }
        });
        mRecyclerView.setAdapter(mAdapter);
        mAdapter.setData(list);
        mAdapter.notifyDataSetChanged();


        tv_more.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(context, ShortMoreActivity.class);
                context.startActivity(intent);
            }
        });

    }


//    @Override
////    public void setData(List<NewsItem> list) {
////        if (!TextUtils.isEmpty(text)) {
////            Spannable string = new SpannableString(iListShowData.getDataTitle());
////            // 粗体
////            string.setSpan(new StyleSpan(Typeface.BOLD), 0, text.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
////            title.setText(string);
////        }
////    }
}
